package com.laogao.lesson068;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;

public class AesEncryptDecryptExample {
    static ObjectMapper objectMapper = new ObjectMapper();

    public static void main(String[] args) throws JsonProcessingException {
        // 密钥，AES 要求密钥长度为 128, 192, 256 位
        String key = "1234567890123456"; // 128位

        // 待加密的字符串
        String content = objectMapper.writeValueAsString(Arrays.asList("老高", "高并发", "微服务", "性能调优实战"));

        AES aes = SecureUtil.aes(key.getBytes(StandardCharsets.UTF_8));
        //加密
        String encrypt = aes.encryptHex(content);
        System.out.println("加密结果:" + encrypt);

        //解密
        String decrypt = aes.decryptStr("c3719d4aee014b3d03579b77200e4093331b9d3fc44f315b9f54ebdfeba3905284bdde5fb4ff2e9e72f51288e09f482d1d60dc2123b7b31dd9aaaf651bda1c13");
        System.out.println("解密结果:" + decrypt);
    }
}